package com.qztc.controller;

import com.qztc.hire_end_dto.dto.HanFuSize;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import java.util.List;

import static com.qztc.config.GlobalConfig.SERVICE_URL;

@RestController
@RequestMapping("/consumer/hanfuSize")
@Tag(name = "消费者端汉服尺码管理接口")
public class HanFuSizeControllerByRestTemplate {
    @Autowired
    private RestTemplate restTemplate;

    @Operation(summary = "获取所有汉服尺码")
    @GetMapping("/getAll")
    public String getAll(){
        return restTemplate.getForObject(SERVICE_URL+"/hanfuSize/getAll", String.class);
    }

    @Operation(summary = "获取具体尺码")
    @GetMapping("getbyhanfuSizeId")
    public String getbyhanfuSizeId(@RequestParam Integer hanFuSizeId){
        return restTemplate.getForObject(SERVICE_URL+"/hanfuSize/getbyhanfuSizeId?hanFuSizeId="+hanFuSizeId, String.class);
    }

    @Operation(summary = "增加尺码")
    @PostMapping("/add")
    public String add(@RequestBody HanFuSize hanFuSize){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<HanFuSize> entity = new HttpEntity<>(hanFuSize, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/hanfuSize/add", HttpMethod.POST,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "删除尺码")
    @DeleteMapping("/delete")
    public String delete(@RequestBody HanFuSize hanFuSize){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<HanFuSize> entity = new HttpEntity<>(hanFuSize, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/hanfuSize/delete", HttpMethod.DELETE,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "修改尺码")
    @PutMapping("/update")
    public String update(@RequestBody HanFuSize hanFuSize){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<HanFuSize> entity = new HttpEntity<>(hanFuSize, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/hanfuSize/update", HttpMethod.PUT,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "批量删除尺码")
    @DeleteMapping("/deleteMany")
    public String deleteMany(@RequestBody List<Integer> hanfuSizeIds){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<List<Integer>> entity = new HttpEntity<>(hanfuSizeIds, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/hanfuSize/deleteMany", HttpMethod.DELETE,entity, String.class);
        return result.getBody();
    }

    @Operation(summary = "批量增加尺码")
    @PostMapping("/addMany")
    public String addMany(@RequestBody List<HanFuSize> hanFuSizes){
        HttpHeaders headers = new HttpHeaders();
        headers.setContentType(MediaType.APPLICATION_JSON);
        HttpEntity<List<HanFuSize>> entity = new HttpEntity<>(hanFuSizes, headers);
        ResponseEntity<String> result = restTemplate.exchange(SERVICE_URL+"/hanfuSize/addMany", HttpMethod.POST,entity, String.class);
        return result.getBody();
    }
}
